<template>
	<div id="profit">
		<div class="details">
			<div v-show="module==0">
				<div class="detailedProfit">
					<div class="unit">￥</div>
					<span class="number">{{message.profit}}</span>
					<div class="empty"></div>
				</div>
				<div class="rate">
					<span>本月收益率</span><span v-text="message.profitRate+'%'"></span>
				</div>
				<div class="wrongDate">
					<div class="warningContainer" v-show="wrongDate">暂无该时间段数据</div>
				</div>
			</div>
			<return-error v-show="module==1"></return-error>
			<return-empty v-show="module==2"></return-empty>
		</div>
	</div>
</template>
<script>
	import RemoteDAO from '@/common/remoteDAO'

	export default{
		data(){
			return {
				module:0,
				message:{
					profit:'',
					profitRate:''
				},
				thisDate:{
					month:'',
					year:''
				}
			}
		},
		props:{
			time:{
				type:String
			},
			wrongDate:{
				type:Boolean
			},
			monthstatus:{
				type:Number
			}
		},
		created(){
			this.initEvent();
		},
		watch:{
			time:function(){
				this.initEvent()
			},
			monthstatus:function(){
				this.initEvent()
			}
		},
		methods:{
			initEvent(){
				this.module=0

				var self=this
				var obj={"pagenum": "30","recent": this.time}
				RemoteDAO.callZL13100007(obj,self.ZL13100007)
				RemoteDAO.callZL13100040(obj,self.ZL13100040)
			},
			ZL13100007(result){
				if(result.error=='1'){
					this.module=1
				}
				else{
					let data=result.data;
					let bigdata=JSON.parse(data).body[0].bigdata;
					let specData=JSON.parse(bigdata).hits.hits;
					if(specData.length==0){
						this.module=2
					}
					else{
						this.message.profit=specData[0]._source.total_profit_total.toFixed(2);
					}
				}
			},
			ZL13100040(result){
				if(result.error=='1'){
					this.module=1
				}
				else{
					let data=result.data;
					let bigdata=JSON.parse(data).body[0].bigdata;
					let specData=JSON.parse(bigdata).hits.hits;
					if(specData.length==0){
						this.module=2
					}
					else{
						this.message.profitRate=(specData[0]._source.total_profit_total_rate*100).toFixed(2);
					}
				}
			}
		}
	}
</script>
<style scoped>
	.detailedProfit {
		height: 60px;
		font-size: 60px;
		line-height: 60px;
		display: flex;
		justify-content: center;
		align-items: baseline;
	}
	.unit,.empty{
		width: 1px;
		flex-grow: 1;
	}
	.unit {
		font-size: 32px;
		text-align: right;
	}

	.number {
		font-size: 60px;
		line-height: 60px;
		padding: 0 10px;
	}

	.rate {
		height: 24px;
		margin-top: 30px;
		opacity: 0.8;
		font-size: 24px;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.rate span {
		padding: 0 10px;
	}

	.wrongDate{
		margin-top: 10px;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.wrongDate .warningContainer{
		padding: 10px 30px;
		background: rgba(0,0,0,0.5);
		font-size: 24px;
		color: #fff;
		border-radius: 4px;
	}
</style>
